package com.yuwei.module_property.viewmodel

import androidx.lifecycle.MutableLiveData
import com.bw.lib_common.vm.BaseViewModel2
import com.yuwei.http.entity.PropertyEntity
import com.yuwei.http.entity.TenantEntity
import com.yuwei.module_property.model.PropertyRepository
import kotlinx.coroutines.launch

class PropertyViewModel: BaseViewModel2<PropertyRepository>() {
    override fun createRepository(): PropertyRepository = PropertyRepository()
    val getPropertySuccess by lazy {
        MutableLiveData<PropertyEntity>()
    }
    val getTenantSuccess by lazy {
        MutableLiveData<TenantEntity>()
    }
    fun getPropertyList(regionId:Int){
        mViewModelScope.launch(mDispatcher) {
            val res = mRepository.getPropertyList(regionId)
            if (res.code == 200){
                getPropertySuccess.postValue(res.data)
            }else{
                mErrorLiveData.postValue(res.message)
            }
        }
    }
    fun getTenantList(){
        mViewModelScope.launch(mDispatcher) {
            val res = mRepository.getTenantList()
            if (res.code == 200){
                getTenantSuccess.postValue(res.data)
            }else{
                mErrorLiveData.postValue(res.message)
            }
        }
    }


}